﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.ajax
{
    /// <summary>
    /// GetAllUserInfos 的摘要说明
    /// </summary>
    public class GetAllUserInfos : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            int page = context.GetValueByName<int>("page");
            int rows = context.GetValueByName<int>("rows");

            using (var db = new PermissionContext())
            {
                var users = db.sys_UserInfo;
                
                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = users.Count(),
                    rows = users
                            .Skip((page - 1) * rows).Take(rows)
                            .Select(k => new { uname = k.U_CName, email = k.U_Email }).ToList()
                }));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}